class ListNode {
  int val;
  ListNode next;
  ListNode() {}
  ListNode(int val) { this.val = val; }
  ListNode(int val, ListNode next) { this.val = val; this.next = next; }
}
public class Solution {
    public ListNode swapPairs(ListNode head) {
        ListNode newHead = new ListNode();
        newHead.next = head;
        ListNode prev = newHead;
        ListNode cur = head;
        while(cur != null && cur.next != null){
            ListNode next = cur.next;
            ListNode tmp = next.next;
            prev.next = next;
            next.next = cur;
            cur.next = tmp;
            prev = cur;
            cur = cur.next;
        }
        return newHead.next;
    }
}